package jdbc;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBC {
	public static void main(String[] args) throws SQLException {
//		testOracle();
		testMysql();
	}

	private static void testMysql() throws SQLException {
//		try {
//			Class.forName("com.mysql.jdbc.Driver");
//		} catch (Exception e) {
//		}
		Driver drv = new com.mysql.jdbc.Driver();
		DriverManager.registerDriver(drv);
		Connection con = DriverManager.getConnection(
				"jdbc:mysql://127.0.0.1:3306/hean", "root", "1234");
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("select id from s_emp");
		String s = null;
		while(rs.next()){
			s = rs.getString("id");
			System.out.println(s);
		}
	}

	private static void testOracle() throws SQLException {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (Exception e) {
		}
		Connection con = DriverManager.getConnection(
				"jdbc:oracle:thin:@172.16.1.230:1521:tarena", "scott", "tiger");
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("select id from s_emp");
		String s = null;
		while(rs.next()){
			s = rs.getString("id");
			System.out.println(s);
		}
	}
}
